package org.jypj.dev.util.work;

import org.jypj.dev.constant.JpushConstant;
import org.jypj.dev.model.GiveWork;
import org.jypj.dev.util.DateUtils;
import org.jypj.dev.util.HxUtil;
import org.jypj.dev.vo.hxVo.PushObject;

import java.util.HashSet;
import java.util.List;
import java.util.Set;


/**
 * 派班工具类
 */
public class GiveWorkUtil {

    /**
     * 提醒叫班
     *
     * @param giveWorks
     * @return
     */
    public static Set<String> remindWork(List<GiveWork> giveWorks) {
        Set<String> ids = new HashSet<>();
        Set<String> users = new HashSet<>();
        for (GiveWork work : giveWorks) {
            String remindTime = work.getWorkDate() + " " + work.getRemindTime();
            String currentTime = DateUtils.getTodayString("yyyy-MM-dd HH:mm");
            if (remindTime.compareTo(currentTime) <= 0) {
                work.setIsRemind(1);
                //推送
                ids.add("'" + work.getId() + "'");
                PushObject pushObject = new PushObject();
                pushObject.setPushType(JpushConstant.REMIND_WORK);
                pushObject.setPushTitle("工作提醒");
                pushObject.setPushContent(work.getWorkDate() + "有新的工作。");
                pushObject.setPushValue(work);
                if (!users.contains(work.getUserNum())) {
                    HxUtil.sendMsgToOneUser(work.getUserNum(), pushObject);
                }
                users.add(work.getUserNum());
            }
        }
        return ids;
    }
}
